﻿#region Copyright

// All Material Copyright © 2010 Dynamic Concepts Development Corp., All Rights Reserved.
//      Portions Copyright © 1984-2009 Dynamic Concepts Development Corp., All Rights Reserved.
// For further information please contact: SoftwareSupport@dynconcepts.com
// Dynamic Concepts Development Corp.  311 W 57th St. Suite #422, New York, NY 10019

#endregion

#region Using References

using System.Collections.Generic;
using System.Windows.Input;

#endregion

namespace DynConDevCorp.OpenArch.DynAppFramework.Tiers.UserInterface.WPF.Engine
{
    public static class CommandHandlersManager
    {
        #region Public Methods

        public static void CanExecute(object sender, CanExecuteRoutedEventArgs args)
        {
            ICommand command = args.Command;
            ICommandHandler handler;
            if (sr_RegisteredHandlers.TryGetValue(command, out handler))
            {
                handler.CommandCanExecute(sender, args);
            }
        }

        public static void Execute(object sender, ExecutedRoutedEventArgs args)
        {
            ICommand command = args.Command;
            ICommandHandler handler;
            if (sr_RegisteredHandlers.TryGetValue(command, out handler))
            {
                handler.CommandExecuted(sender, args);
            }
        }

        public static void Register(ICommandHandler handler)
        {
            sr_RegisteredHandlers.Add(handler.Command, handler);
        }

        #endregion

        #region Static Fields and Constants

        private static readonly Dictionary<ICommand, ICommandHandler> sr_RegisteredHandlers =
            new Dictionary<ICommand, ICommandHandler>();

        #endregion
    }
}